package com.example.demo.threadPool_countDownLatch.alibba_threadlocal;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.example.demo.threadPool_countDownLatch.plus.ThreadpoolConfig;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: ThreadLocalDemo
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/08/14-10:02:00
 * Description:
 * ThreadLocal: 当前set的值只有当前线程可以get。
 * InheritableThreadLocal: set的值每一个线程都可以get到
 */
public class ThreadLocalDemo {
    public static void main(String[] args) throws InterruptedException {
//        TransmittableThreadLocal<String> inheritableThreadLocal = new TransmittableThreadLocal<>();
//        inheritableThreadLocal.set("我是父亲");

//        ThreadLocal threadLocal=new ThreadLocal();
//        threadLocal.set("我是父亲");
        ExecutorService ttlExecutorService = Executors.newFixedThreadPool(1);
        InheritableThreadLocal<String> inheritableThreadLocal = new InheritableThreadLocal();
        inheritableThreadLocal.set("我是父亲1");


        new Thread(() -> {
            String s = inheritableThreadLocal.get();
            System.out.println(s);

            inheritableThreadLocal.set("我是父亲222");
            System.out.println(inheritableThreadLocal.get());
        }).start();
//        ttlExecutorService.submit(() -> {
//
//            String s = inheritableThreadLocal.get();
//
//            System.out.println(s);
//            //TenantContext.clean();
//
//        });
//
//        inheritableThreadLocal.set("我是父亲22");
//
//        ttlExecutorService.submit(() -> {
//            String s = inheritableThreadLocal.get();
//
//            System.out.println(s);
//
//
//        });

    }
}
